let list = [
  {
    id: 1,
    deptName: 'John Brown',
    parentId: 0,
    age: 32,
    address: 'New York No. 1 Lake Park',
  },
]

export default {
  'GET  /api/v1/dept': {
    data: list,
    total: list.length,
    page: 1,
    success: true
  },
  'POST /api/v1/dept/': async (req: Request, res: Response) => {
    const { deptName, parentId } = req.body as any;

    list.push({
      id: list.length + 1,
      deptName,
      parentId,
      age: 32,
      address: 'New York No. 1 Lake Park',
    })
    res.send({
      success: true
    });
  },
  'PUT /api/v1/dept/1': async (req: Request, res: Response) => {
    console.log('request', req)
    const { deptName, parentId } = req.body as any;

    const one = list.find(l => l.id === 1)
    if (one) {
      one.deptName = deptName
      one.parentId = parentId
    }
    res.send({
      success: true,
      one
    });
  },
  'DELETE /api/v1/dept/1': async (req: Request, res: Response) => {

    list = list.filter((l) => l.id != 1)
    res.send({
      success: true,
    });
  },
};

